// bdf_to_cdb_convert.h
#ifndef BDF_TO_CDB_CONVERT_H
#define BDF_TO_CDB_CONVERT_H

#include <string>
#include <vector>
#include <unordered_map>
#include <fstream>

#include "convertor.h"

class BdfToCdbConvert : public Convertor {
public:
    int convert(const std::string& bdfPath, const std::string& cdbPath);

private:
    struct Node {
        int id;
        double x, y, z;
    };
    struct Element {
        int id;
	int pid;
        std::string type;
        std::vector<int> nodes;
    };
    
    struct Property {
    int mid;         // 材料 ID
    double thickness;
    };
  
    struct MaterialInfo {
    int mid;        // 材料 ID
    double e;       // 弹性模量 (Elastic mInfous)
    double nu;      // 泊松比 (Poisson's ratio)
};
    std::unordered_map<int, Property> pidToProperty;
    std::unordered_map<int, MaterialInfo> midToMaterial;
    std::unordered_map<int, int> pidToSectionId;
    std::vector<Node> nodes;
    std::vector<Element> elements;
    std::unordered_map<int, int> nodeIdMap;
    
    int sectionIdBase = 1;
    int parsedBdfFile(const std::string& bdfPath);
    void parseNode(const std::string& line);
    void parseElement(const std::string& line);
    std::string mapBdfElementTypeToCdb(const std::string& bdfType);
    int mapElementTypeToEtType(const std::string& type);
    int generateCdbFile(const std::string& path);
    void writeNodesToCdb(std::ofstream& out);
    void writeElementsToCdb(std::ofstream& out);
    void trim(std::string& s);
    void parseMaterial(const std::string& line);
    void parsePshell(const std::string& line);
    void parseMat1(const std::string& line);
    void writeHeader(std::ofstream& out);
    std::vector<std::string> split(const std::string& s, char delimiter);
};

#endif // BDF_TO_CDB_CONVERT_H
